package com.atguigu.redis;

import com.atguigu.constant.RedisConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class RedisMessageReceiver {
    @Autowired
    private RedisTemplate redisTemplate;
    public void receiveChannelMessage(String message){
        //传过来的消息格式是 ""24:1""  需要将多余的""去掉
        if (!StringUtils.isEmpty(message)){
            message = message.replaceAll("\"", "");
            String[] split = message.split(":");
            if (split.length == 2){
                //将商品的状态值添加到redis中
                redisTemplate.opsForValue().set(RedisConst.SECKILL_STATE_PREFIX+split[0],split[1]);
            }
        }
    }
}
